<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<script>
var lengthOfLongestSubstring = function(s) {
    let left = 0
    let right = 0
    let s1 = s[0]
    let num = 1
    let length = s.length
    while (right < (length - 1)) {
        right++
        // console.log('s1:', s1)
        // console.log('left:', left)
        // console.log('right:', right)
        // console.log('s[right]:', s[right])
        if (s1.indexOf(s[right]) !== -1) {
            num = Math.max(num, s1.length)
            console.log('----------------------')
            left = s1.indexOf(s[right]) + 1 + left
        } else {
            console.log('````````````````````')
        }
        s1 = s.substring(left, right+1)
    }
    num = Math.max(num, s1.length)
    return num
}
// var s = "abcabcbb"
// var s = "bbbbb"
var s = "ab"

console.log('s:', s)
console.log(lengthOfLongestSubstring(s))



</script>
</body>
</html>